# -*- mode:Makefile -*-
include ../Makefile.common
LANG=ruby
CXXFLAGS+=-I.. -I../ext
BASEDIR=..
DISTCLEANOBJ+=Makefile.ruby extconf.rb
CLEANOBJ+=$(DISTCLEANOBJ)
TARGET=$(MODULE).so

do:$(TARGET)
$(TARGET): $(MODULE)_wrap.cpp Makefile.ruby
	$(MAKE) -f Makefile.ruby LDSHARED="$(CXX) -shared ../$(MODULE).o ../$(MODULE)Plugin.o"
$(MODULE)_wrap.cpp: $(BASEDIR)/$(MODULE).i
	$(SWIG) -c++ -$(LANG) -autorename -o $@ $(BASEDIR)/$(MODULE).i
Makefile.ruby: extconf.rb
	mv Makefile Makefile.tmp
	cp Makefile.tmp Makefile
	ruby extconf.rb
	mv Makefile $@
	mv Makefile.tmp Makefile
extconf.rb: Makefile
	echo "require 'mkmf'" > $@
	echo -n "$$" >> $@
	echo "CFLAGS += \" ${QUOTE_CXXFLAGS}\"" >> $@
	echo -n "$$" >> $@
	echo "LDFLAGS += \" ${LDFLAGS}\"" >> $@
	echo "create_makefile('${MODULE}')" >> $@
install: Makefile.ruby
	$(MAKE) -f Makefile.ruby install
#	cp $(TARGET) $(RUBYLIB)